package com.cedar.demo.service;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.omg.CORBA.Any;
import org.omg.CORBA.TCKind;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNotification.StructuredEvent;
import org.omg.CosNotification.Property;
import org.omg.DynamicAny.DynAnyFactory;
import org.omg.DynamicAny.DynAnyFactoryHelper;
import org.omg.DynamicAny.DynArray;
import org.omg.DynamicAny.DynEnum;
import org.omg.DynamicAny.DynSequence;
import org.omg.DynamicAny.DynStruct;
import org.omg.DynamicAny.DynUnion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import com.cedar.demo.demo.MeData;
import com.cedar.demo.entity.CorbaLoginReq;
import com.cedar.demo.entity.CorbaLoginRes;
import com.cedar.demo.entity.TANmsSession_IImpl;
import com.cedar.demo.utils.JsonUtils;

import mtnm.tmforum.org.common.Common_IHolder;
import mtnm.tmforum.org.emsMgr.AlarmStaticInfoIterator_IHolder;
import mtnm.tmforum.org.emsMgr.AlarmStaticInfoList_THolder;
import mtnm.tmforum.org.emsMgr.AlarmStaticInfo_T;
import mtnm.tmforum.org.emsMgr.EMSMgr_I;
import mtnm.tmforum.org.emsMgr.EMSMgr_IHelper;
import mtnm.tmforum.org.emsSession.EmsSession_I;
import mtnm.tmforum.org.emsSession.EmsSession_IHolder;
import mtnm.tmforum.org.emsSession.EmsSession_IPackage.managerNames_THolder;
import mtnm.tmforum.org.emsSessionFactory.EmsSessionFactory_I;
import mtnm.tmforum.org.emsSessionFactory.EmsSessionFactory_IHelper;
import mtnm.tmforum.org.equipment.EquipmentInventoryMgr_I;
import mtnm.tmforum.org.equipment.EquipmentInventoryMgr_IHelper;
import mtnm.tmforum.org.equipment.EquipmentOrHolderIterator_IHolder;
import mtnm.tmforum.org.equipment.EquipmentOrHolderList_THolder;
import mtnm.tmforum.org.equipment.EquipmentOrHolder_T;
import mtnm.tmforum.org.equipment.ObjectAdditionalInfoList_THolder;
import mtnm.tmforum.org.equipment.ObjectAdditionalInfo_T;
import mtnm.tmforum.org.equipment.PhysicalLocationInfoList_THolder;
import mtnm.tmforum.org.equipment.PhysicalLocationInfo_T;
import mtnm.tmforum.org.globaldefs.NameAndStringValue_T;
import mtnm.tmforum.org.globaldefs.NamingAttributesIterator_IHolder;
import mtnm.tmforum.org.globaldefs.NamingAttributesList_THolder;
import mtnm.tmforum.org.globaldefs.ProcessingFailureException;
import mtnm.tmforum.org.managedElement.ManagedElementIterator_IHolder;
import mtnm.tmforum.org.managedElement.ManagedElementList_THolder;
import mtnm.tmforum.org.managedElement.ManagedElement_T;
import mtnm.tmforum.org.managedElement.ManagedElement_THolder;
import mtnm.tmforum.org.managedElementManager.ManagedElementMgr_I;
import mtnm.tmforum.org.managedElementManager.ManagedElementMgr_IHelper;
import mtnm.tmforum.org.multiLayerSubnetwork.MultiLayerSubnetworkMgr_I;
import mtnm.tmforum.org.multiLayerSubnetwork.MultiLayerSubnetworkMgr_IHelper;
import mtnm.tmforum.org.multiLayerSubnetwork.MultiLayerSubnetwork_T;
import mtnm.tmforum.org.multiLayerSubnetwork.SubnetworkIterator_IHolder;
import mtnm.tmforum.org.multiLayerSubnetwork.SubnetworkList_THolder;
import mtnm.tmforum.org.nmsSession.NmsSession_I;
import mtnm.tmforum.org.nmsSession.NmsSession_IPOA;
import mtnm.tmforum.org.notifications.EventIterator_IHolder;
import mtnm.tmforum.org.notifications.EventList_THolder;
import mtnm.tmforum.org.notifications.PerceivedSeverity_T;
import mtnm.tmforum.org.performance.CollectTaskInfoList_THolder;
import mtnm.tmforum.org.performance.CollectTaskInfo_T;
import mtnm.tmforum.org.performance.PerformanceManagementMgr_I;
import mtnm.tmforum.org.performance.PerformanceManagementMgr_IHelper;
import mtnm.tmforum.org.subnetworkConnection.CCIterator_IHolder;
import mtnm.tmforum.org.subnetworkConnection.CrossConnectList_THolder;
import mtnm.tmforum.org.subnetworkConnection.CrossConnect_T;
import mtnm.tmforum.org.subnetworkConnection.Route_THolder;
import mtnm.tmforum.org.subnetworkConnection.SNCIterator_IHolder;
import mtnm.tmforum.org.subnetworkConnection.SubnetworkConnectionList_THolder;
import mtnm.tmforum.org.subnetworkConnection.SubnetworkConnection_T;
import mtnm.tmforum.org.subnetworkConnection.SubnetworkConnection_THolder;
import mtnm.tmforum.org.terminationPoint.TerminationPointIterator_IHolder;
import mtnm.tmforum.org.terminationPoint.TerminationPointList_THolder;
import mtnm.tmforum.org.terminationPoint.TerminationPoint_T;
import mtnm.tmforum.org.topologicalLink.TopologicalLinkIterator_IHolder;
import mtnm.tmforum.org.topologicalLink.TopologicalLinkList_THolder;
import mtnm.tmforum.org.topologicalLink.TopologicalLink_T;
import mtnm.tmforum.org.topologicalLink.TopologicalLink_THolder;

@Service
public class HuaweiNceCorbaServiceImpl implements HuaweiNceCorbaService{
    @Autowired
	private CorbaLoginReq loginReq;
    
    public CorbaLoginRes login() {
		CorbaLoginRes login = new CorbaLoginRes();
		try {
			String argv[] = new String[2];
			argv[0] = "-ORBInitRef";
			argv[1] = "NameService=corbaloc::" + loginReq.getHost() + ":" + loginReq.getPort() + "/NameService";
			org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(argv, null);
			org.omg.PortableServer.POA rootPOA;
			rootPOA = org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
			rootPOA.the_POAManager().activate();
			DynAnyFactory dynAnyFactory = DynAnyFactoryHelper.narrow(orb.resolve_initial_references("DynAnyFactory"));
			org.omg.CosNaming.NamingContextExt nc = org.omg.CosNaming.NamingContextExtHelper
					.narrow(orb.resolve_initial_references("NameService"));
			org.omg.CosNaming.NameComponent[] name;
			name = new NameComponent[5];
			name[0] = new NameComponent("TMF_MTNM", "Class");
			name[1] = new NameComponent("HUAWEI", "Vendor");
			name[2] = new NameComponent("Huawei/NCE", "EmsInstance");
			name[3] = new NameComponent("2.0", "Version");
			name[4] = new NameComponent("Huawei/NCE", "EmsSessionFactory_I");
			EmsSessionFactory_I emsSessionFactory = EmsSessionFactory_IHelper.narrow(nc.resolve(name));
			NmsSession_IPOA pNmsSessionServant = new TANmsSession_IImpl();
			NmsSession_I NmsSession = pNmsSessionServant._this(orb);
			EmsSession_IHolder emsSessionInterfaceHolder = new EmsSession_IHolder();
			emsSessionFactory.getEmsSession(loginReq.getUserName(), loginReq.getPassWord(), NmsSession, emsSessionInterfaceHolder);
			EmsSession_I emsSession = emsSessionInterfaceHolder.value;
			login.setDynAnyFactory(dynAnyFactory);
			login.setOrb(orb);
			login.setRootPOA(rootPOA);
			login.setEmsSession(emsSession);
			return login;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * @description:获取支持的管理单元
	 * @author:hutao
	 * @throws ProcessingFailureException 
	 * @mail:hutao1@epri.sgcc.com.cn
	 * @date:2024年3月1日 下午4:23:18
	 */
	
	public List<String> getAllSupportedManagers(EmsSession_I emsSession) throws ProcessingFailureException {
		managerNames_THolder managerNamesHolder = new managerNames_THolder();
		emsSession.getSupportedManagers(managerNamesHolder);
		return Arrays.asList(managerNamesHolder.value); 
	}
	
	/**
	 * 获取所有网元
	 */
	
	public List<ManagedElement_T> getAllManagedElements(EmsSession_I emsSession) {
		List<ManagedElement_T> list = null;
		try {
			Common_IHolder commonHolder = new Common_IHolder();
			emsSession.getManager("ManagedElement", commonHolder);
			ManagedElementMgr_I meMgr = ManagedElementMgr_IHelper.narrow(commonHolder.value);
			ManagedElementList_THolder meListHolder = new ManagedElementList_THolder();
			ManagedElementIterator_IHolder meIteratorHolder = new ManagedElementIterator_IHolder();
			meMgr.getAllManagedElements(100, meListHolder, meIteratorHolder);
			System.out.println(meListHolder.value);
			list = Arrays.asList(meListHolder.value);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	
	public ManagedElement_T getManagedElement(EmsSession_I emsSession, String stElement) throws ProcessingFailureException {
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("ManagedElement", commonHolder);
		ManagedElementMgr_I meMgr = ManagedElementMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] managedElementName = new NameAndStringValue_T[2];
		managedElementName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		managedElementName[1] = new NameAndStringValue_T("ManagedElement", stElement);
		ManagedElement_THolder me = new ManagedElement_THolder();
		meMgr.getManagedElement(managedElementName, me);;
		return me.value;
	}

	
	public List<MultiLayerSubnetwork_T> getAllTopLevelSubnetworks(EmsSession_I emsSession) throws ProcessingFailureException {
		List<MultiLayerSubnetwork_T> list = null;
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("EMS", commonHolder);
		EMSMgr_I emsMgr = EMSMgr_IHelper.narrow(commonHolder.value);
		SubnetworkList_THolder subworkListHolder = new SubnetworkList_THolder();
		SubnetworkIterator_IHolder subworkIteratorHolder = new SubnetworkIterator_IHolder();
		emsMgr.getAllTopLevelSubnetworks(500, subworkListHolder, subworkIteratorHolder);
		list = Arrays.asList(subworkListHolder.value);
		return list;
	}

	/**
	 * 获取物理信息
	 */
	
	public List<PhysicalLocationInfo_T> getPhysicalLocationInfo(EmsSession_I emsSession) throws ProcessingFailureException {
		List<PhysicalLocationInfo_T> list = null;
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("EquipmentInventory", commonHolder);
		EquipmentInventoryMgr_I eiMgr = EquipmentInventoryMgr_IHelper.narrow(commonHolder.value);
		PhysicalLocationInfoList_THolder listHolder = new PhysicalLocationInfoList_THolder();
		eiMgr.getPhysicalLocationInfo(listHolder);
		for (PhysicalLocationInfo_T temp : listHolder.value) {
			try {
				temp.getShelf_().setName(new String(temp.getShelf_().getName().getBytes("iso-8859-1")));
				temp.getShelf_().setMemo(new String(temp.getShelf_().getMemo().getBytes("iso-8859-1")));
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		list = Arrays.asList(listHolder.value);
		return list;
	}

	
	public List<EquipmentOrHolder_T> getContainedEquipment(EmsSession_I emsSession, String stElement, String EquipmentHolder) throws ProcessingFailureException {
		List<EquipmentOrHolder_T> list = null;
		Common_IHolder commonHolder = new Common_IHolder(); 
		emsSession.getManager("EquipmentInventory", commonHolder); 
		EquipmentInventoryMgr_I eiMgr = EquipmentInventoryMgr_IHelper.narrow(commonHolder.value);
		EquipmentOrHolderList_THolder listHolder = new EquipmentOrHolderList_THolder();
		NameAndStringValue_T[] equipmentHolderName = new NameAndStringValue_T[3];
		/**
		 * 1.name="EMS"; value="Huawei/NCE"
		   2.name="ManagedElement";value="33554433"
		   3.name="EquipmentHolder";value="/rack=1/shelf=590225/slot=1"
		 */
		equipmentHolderName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		equipmentHolderName[1] = new NameAndStringValue_T("ManagedElement", stElement);
		equipmentHolderName[2] = new NameAndStringValue_T("EquipmentHolder", EquipmentHolder);
		eiMgr.getContainedEquipment(equipmentHolderName,listHolder);
		list = Arrays.asList(listHolder.value);
		return list;

	}
	
	
	public List<TerminationPoint_T> getAllSupportedPTPs(EmsSession_I emsSession, String stElement, String equipmentHolder, String equipment) throws ProcessingFailureException {
		List<TerminationPoint_T> list = null;
		Common_IHolder commonHolder = new Common_IHolder(); 
		emsSession.getManager("EquipmentInventory", commonHolder); 
		EquipmentInventoryMgr_I eiMgr = EquipmentInventoryMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] query = new NameAndStringValue_T[4];
		query[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		query[1] = new NameAndStringValue_T("ManagedElement", stElement);
		query[2] = new NameAndStringValue_T("EquipmentHolder", equipmentHolder);
		query[3] = new NameAndStringValue_T("Equipment", "1");
		TerminationPointList_THolder listHolder = new TerminationPointList_THolder();
		TerminationPointIterator_IHolder itHolder = new TerminationPointIterator_IHolder();
		eiMgr.getAllSupportedPTPs(query, 100, listHolder, itHolder);
		list = Arrays.asList(listHolder.value);
		return list;
	}
	
	public NameAndStringValue_T[][] getEquipmentStaticInfo(EmsSession_I emsSession, String stElement) throws ProcessingFailureException {
		Common_IHolder commonHolder = new Common_IHolder(); 
		emsSession.getManager("EquipmentInventory", commonHolder); 
		EquipmentInventoryMgr_I eiMgr = EquipmentInventoryMgr_IHelper.narrow(commonHolder.value);
		String[] typeList = new String [1];
		typeList[0] = "N2PQ1(868)";
		NamingAttributesList_THolder maListHolder = new NamingAttributesList_THolder();
		NamingAttributesIterator_IHolder maItHolder = new NamingAttributesIterator_IHolder();
		eiMgr.getEquipmentStaticInfo(typeList, 100, maListHolder, maItHolder);
		return maListHolder.value;
	}

	/**
	 * 获取指定网元的所有设备
	 */
	
	public List<EquipmentOrHolder_T> getAllEquipment(EmsSession_I emsSession, String stElement) throws ProcessingFailureException {
		List<EquipmentOrHolder_T> list = null;
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("EquipmentInventory", commonHolder);
		EquipmentInventoryMgr_I mgr = EquipmentInventoryMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] query = new NameAndStringValue_T[2];
		query[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		query[1] = new NameAndStringValue_T("ManagedElement", stElement);
		EquipmentOrHolderList_THolder eqList = new EquipmentOrHolderList_THolder();
		EquipmentOrHolderIterator_IHolder eqIt = new EquipmentOrHolderIterator_IHolder();
		mgr.getAllEquipment(query, 200, eqList, eqIt);
		list = Arrays.asList(eqList.value);
		return list;
	}
	
	
	public NameAndStringValue_T[][] getAllEquipmentNames(EmsSession_I emsSession, String stElement) throws ProcessingFailureException {
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("EquipmentInventory", commonHolder);
		EquipmentInventoryMgr_I eiMgr = EquipmentInventoryMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] meOrHolderName = new NameAndStringValue_T[2];
		meOrHolderName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		meOrHolderName[1] = new NameAndStringValue_T("ManagedElement", stElement);
		NamingAttributesList_THolder eqList = new NamingAttributesList_THolder();
		NamingAttributesIterator_IHolder eqIt = new NamingAttributesIterator_IHolder();
		eiMgr.getAllEquipmentNames(meOrHolderName, 100, eqList, eqIt);
		NameAndStringValue_T[][] value = eqList.value;
		return value;
	}

	
	public List<TopologicalLink_T> getTopologicalLink(EmsSession_I emsSession) throws ProcessingFailureException {
		List<TopologicalLink_T> list = null;
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("MultiLayerSubnetwork", commonHolder);
		MultiLayerSubnetworkMgr_I misMgr = MultiLayerSubnetworkMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] meOrHolderName = new NameAndStringValue_T[2];
		meOrHolderName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		meOrHolderName[1] = new NameAndStringValue_T("TopologicalLink","1422607342-1-3145734-3145739");
		TopologicalLink_THolder topoLink = new TopologicalLink_THolder();
		misMgr.getTopologicalLink(meOrHolderName, topoLink);
		list = Arrays.asList(topoLink.value);
		return list;
	}

	
	public List<ObjectAdditionalInfo_T> getAllEquipmentAdditionalInfo(EmsSession_I emsSession, String stElement) throws ProcessingFailureException {
		List<ObjectAdditionalInfo_T> list = null;
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("EquipmentInventory", commonHolder);
		EquipmentInventoryMgr_I eiMgr = EquipmentInventoryMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] meOrHolderName = new NameAndStringValue_T[2];
		meOrHolderName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		meOrHolderName[1] = new NameAndStringValue_T("ManagedElement", stElement);
		ObjectAdditionalInfoList_THolder listHolder = new ObjectAdditionalInfoList_THolder();
		eiMgr.getAllEquipmentAdditionalInfo(meOrHolderName, listHolder);
		list = Arrays.asList(listHolder.value);
		return list;
	}
	
	
	public List<CrossConnect_T> getAllCrossConnections(EmsSession_I emsSession, String stElement, String rate) throws ProcessingFailureException {
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("ManagedElement", commonHolder);
		ManagedElementMgr_I meMgr = ManagedElementMgr_IHelper.narrow(commonHolder.value);

		NameAndStringValue_T[] managedElementName = new NameAndStringValue_T[2];
		managedElementName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		managedElementName[1] = new NameAndStringValue_T("ManagedElement", stElement);
		String[] split = rate.split(",");
		short[] connectionRateList = new short[split.length];
		for (int i = 0; i < split.length; i++) {
			connectionRateList[i] = Short.parseShort(split[i]);
		}
		CrossConnectList_THolder ccList = new CrossConnectList_THolder();
		CCIterator_IHolder ccIt = new CCIterator_IHolder();
		meMgr.getAllCrossConnections(managedElementName, connectionRateList, 5000, ccList, ccIt);
		return Arrays.asList(ccList.value);
	}
	
	
	public List<SubnetworkConnection_T> getAllSubnetworkConnections(EmsSession_I emsSession, String subnet, String rate) throws ProcessingFailureException{
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("MultiLayerSubnetwork", commonHolder);
		MultiLayerSubnetworkMgr_I misMgr = MultiLayerSubnetworkMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] subnetName = new NameAndStringValue_T[2];
		subnetName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		subnetName[1] = new NameAndStringValue_T("MultiLayerSubnetwork", subnet);
		String[] split = rate.split(",");
		short[] connectionRateList = new short[split.length];
		for (int i = 0; i < split.length; i++) {
			connectionRateList[i] = Short.parseShort(split[i]);
		}
		SubnetworkConnectionList_THolder sncList = new SubnetworkConnectionList_THolder();
		SNCIterator_IHolder sncIt = new SNCIterator_IHolder();
		misMgr.getAllSubnetworkConnections(subnetName, connectionRateList, 20000, sncList, sncIt);
		return Arrays.asList(sncList.value);
	}
	
	
	public List<TopologicalLink_T> getAllTopologicalLinks(EmsSession_I emsSession, String subnetwork) throws ProcessingFailureException {
		List<TopologicalLink_T> list = null;
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("MultiLayerSubnetwork", commonHolder);
		MultiLayerSubnetworkMgr_I misMgr = MultiLayerSubnetworkMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] subnetName = new NameAndStringValue_T[2];
		subnetName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		subnetName[1] = new NameAndStringValue_T("MultiLayerSubnetwork", "1");
		TopologicalLinkList_THolder topoList = new TopologicalLinkList_THolder();
		TopologicalLinkIterator_IHolder topoIt = new TopologicalLinkIterator_IHolder();
		misMgr.getAllTopologicalLinks(subnetName, 50000, topoList, topoIt);
		list = Arrays.asList(topoList.value);
		return list;
	}
	
	
	public List<CrossConnect_T> getRoute(EmsSession_I emsSession, String subnetworkConnection) throws ProcessingFailureException {
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("MultiLayerSubnetwork", commonHolder);
		MultiLayerSubnetworkMgr_I misMgr = MultiLayerSubnetworkMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] sncName = new NameAndStringValue_T[3];
		sncName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		sncName[1] = new NameAndStringValue_T("MultiLayerSubnetwork", "1");
		sncName[2] = new NameAndStringValue_T("SubnetworkConnection", subnetworkConnection/*"2022-03-14 09:00:44 - 2166-sdh"*/);
		boolean includeHigherOrderCCs = true;
		Route_THolder route = new Route_THolder();
		misMgr.getRoute(sncName, includeHigherOrderCCs, route);
		return Arrays.asList(route.value);
	}
	
	public SubnetworkConnection_T getSNC(EmsSession_I emsSession) throws ProcessingFailureException {
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("MultiLayerSubnetwork", commonHolder);
		MultiLayerSubnetworkMgr_I misMgr = MultiLayerSubnetworkMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] sncName = new NameAndStringValue_T[3];
		sncName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		sncName[1] = new NameAndStringValue_T("MultiLayerSubnetwork", "1");
		sncName[2] = new NameAndStringValue_T("SubnetworkConnection", "2020-08-20 10:07:07 - 1321-sdh");
		SubnetworkConnection_THolder snc = new SubnetworkConnection_THolder();
		misMgr.getSNC(sncName, snc);
		return snc.value;
	}
	
	public List<CrossConnect_T> getOrginalRoute(EmsSession_I emsSession) throws ProcessingFailureException {
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("MultiLayerSubnetwork", commonHolder);
		MultiLayerSubnetworkMgr_I misMgr = MultiLayerSubnetworkMgr_IHelper.narrow(commonHolder.value);
		NameAndStringValue_T[] sncName = new NameAndStringValue_T[3];
		sncName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		sncName[1] = new NameAndStringValue_T("MultiLayerSubnetwork", "1");
		sncName[2] = new NameAndStringValue_T("SubnetworkConnection", "2020-08-20 10:07:07 - 1321-sdh");
		boolean includeHigherOrderCCs = true;
		Route_THolder route = new Route_THolder();
		misMgr.getOrginalRoute(sncName, includeHigherOrderCCs, route);
		return Arrays.asList(route.value);
	}
	
	
	public List<MeData> neAllRelation() throws ProcessingFailureException {
		List<MeData> list = new ArrayList<>();
		EmsSession_I login = this.login().getEmsSession();
		List<ManagedElement_T> allManagedElements = this.getAllManagedElements(login);
		Map<String, List<EquipmentOrHolder_T>> neToEq = new HashMap<>();
		Map<String, List<EquipmentOrHolder_T>> slotToCard = new HashMap<>();
		Map<String, List<TerminationPoint_T>> cardToPort = new HashMap<>();
		for (ManagedElement_T me : allManagedElements) {
			if(me.getProductName().contains("Virtual")) {
				continue;
			}
			MeData medata = new MeData();
			String meId = null;
			for (NameAndStringValue_T name: me.getName()) {
				if("ManagedElement".equals(name.getName())) {
					meId = name.getValue();
				}
			}
			//ME和设备映射
			if(!ObjectUtils.isEmpty(meId)) {
				List<EquipmentOrHolder_T> allEquipment = this.getAllEquipment(login, meId);
				neToEq.put(meId, allEquipment);
				int index = 1;
				for (EquipmentOrHolder_T eq : allEquipment) {
					//设备中的槽位loft和板卡映射
					if(eq.getHolder()!= null && eq.getHolder().getHolderState()!= null && "slot".equals(eq.getHolder().getHolderType())) {
						System.out.println("第"+index+"个槽位");
						index ++;
						NameAndStringValue_T equipmentHolder = eq.getHolder().getName()[2];
						List<EquipmentOrHolder_T> containedEquipment = this.getContainedEquipment(login, meId, equipmentHolder.getValue());
						slotToCard.put(meId + "-" + equipmentHolder.getValue(), containedEquipment);
						for (EquipmentOrHolder_T card : containedEquipment) {
							if(!ObjectUtils.isEmpty(card)) {
								List<TerminationPoint_T> allSupportedPTPs = this.getAllSupportedPTPs(login, meId, equipmentHolder.getValue(), card.getEquip().name[3].value);
								cardToPort.put(meId+"-"+equipmentHolder.getValue() + "-" + card.getEquip().name[3].value, allSupportedPTPs);
							}
						}
					}
				}
				medata.setSlotToCard(slotToCard);
				medata.setNeToEq(neToEq);
				medata.setCardToPort(cardToPort);
			}
			medata.setMe(me);
			String strMe = JsonUtils.javaBeanToString(medata);
			try {
				JsonUtils.initFileJson("C:\\workspace\\me\\"+meId+".json", new String(strMe.getBytes("iso-8859-1")));
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			list.add(medata);
		}
		return list;
	}
	
	
	
	public void getAllHistoryAlarmsByFTP(EmsSession_I emsSession) throws ProcessingFailureException{
		Common_IHolder commonHolder = new Common_IHolder();
		emsSession.getManager("EMS", commonHolder);
		EMSMgr_I emsMgr = EMSMgr_IHelper.narrow(commonHolder.value);
		//String destination = "192.168.60.99:/opt/backup/ftpboot/abcd.txt";
		String destination = "192.168.60.99:abcd.txt";
		String userName = "ftpuser";
		String password = "Changeme_123";
		NameAndStringValue_T[][] meNameList = new NameAndStringValue_T[1][];//网元名称列表（与typeList 条件不能同时输入）。仅支持网元/光网元，不支持EMS/SNMS。
		NameAndStringValue_T[] meName = new NameAndStringValue_T[2];
		meName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		meName[1] = new NameAndStringValue_T("ManagedElement", "167772252");
		meNameList[0] = meName;
		String[] typeList = new String[0];//网元类型列表（与meNameList 条件不能同时输入）
		String[] excludeProbCauseList = new String[0];//符合此类原因的告警不查询。列表为空标识不使用该过滤条件。
		PerceivedSeverity_T[] excludeSeverityList = new PerceivedSeverity_T[0];//符合此类级别的告警不查询，列表为空标识不使用该过滤条件。
		String startTime = "20230301000000.0";//起始时间（格式如：20130111000000.0 Z 本地时间及UTC时间均支持）针对告警的清除时间进行过滤，不包括起始时间点。
		String endTime = "20240307000000.0";//终止时间（格式如：20130111000000.0 Z 本地时间及UTC时间均支持）针对告警的清除时间进行过滤，包括终止时间点。
		emsMgr.getAllHistoryAlarmsByFTP(destination, userName, password, meNameList, typeList, excludeProbCauseList, excludeSeverityList, startTime, endTime);
	}
	
	
	public List<Map<String, String>> getAllEMSAndMEActiveAlarms(CorbaLoginRes login) throws ProcessingFailureException{
		List<Map<String, String>> list = new ArrayList<>();
		
		Common_IHolder commonHolder = new Common_IHolder();
		login.getEmsSession().getManager("EMS", commonHolder);
		EMSMgr_I emsMgr = EMSMgr_IHelper.narrow(commonHolder.value);
		EventList_THolder eventList = new EventList_THolder();
		EventIterator_IHolder eventIt = new EventIterator_IHolder();
		String[] excludeProbCauseList = new String[0];//符合此类原因的告警不查询。列表为空标识不使用该过滤条件。
		PerceivedSeverity_T[] excludeSeverityList = new PerceivedSeverity_T[0];//符合此类级别的告警不查询，列表为空标识不使用该过滤条件。
		emsMgr.getAllEMSAndMEActiveAlarms(excludeProbCauseList, excludeSeverityList, 5000, eventList, eventIt);
		for (StructuredEvent temp : eventList.value) {
			Map<String, String> data = new HashMap<>();
			for (Property t : temp.filterable_data) {
				data.put(t.name, this.parseAny(t.value, login.getDynAnyFactory()));
			}
			list.add(data);
		}
		return list;
	}
	
	
	public List<AlarmStaticInfo_T> getAllAlarmStaticInfo(CorbaLoginRes login) throws ProcessingFailureException{
		Common_IHolder commonHolder = new Common_IHolder();
		login.getEmsSession().getManager("EMS", commonHolder);
		EMSMgr_I emsMgr = EMSMgr_IHelper.narrow(commonHolder.value);
		AlarmStaticInfoList_THolder alarmInfoList = new AlarmStaticInfoList_THolder();
		AlarmStaticInfoIterator_IHolder alarmInfoIt = new AlarmStaticInfoIterator_IHolder();
		emsMgr.getAllAlarmStaticInfo(500, alarmInfoList, alarmInfoIt);
		return Arrays.asList(alarmInfoList.value);
	}
	
	
	public void createPMCollectionTask(CorbaLoginRes login) throws ProcessingFailureException {
		//这个接口参数传参报错，现在还没摸清楚，怎么传参
		Common_IHolder commonHolder = new Common_IHolder();
		login.getEmsSession().getManager("PerformanceManagement", commonHolder);
		PerformanceManagementMgr_I pmMgr = PerformanceManagementMgr_IHelper.narrow(commonHolder.value);
		String taskName = "xing_neng_ce_shi";
		String destination = "192.168.60.99:/pfmdata.txt"; //10.70.73.96:/pfmdata.csv
		String userName = "ftpuser";
		String password = "Changeme_123";
		String emsUserName = "test";
		NameAndStringValue_T[][] pmTPSelectList = new NameAndStringValue_T[1][];
		NameAndStringValue_T[] meName = new NameAndStringValue_T[2];
		meName[0] = new NameAndStringValue_T("EMS", "Huawei/NCE");
		meName[1] = new NameAndStringValue_T("ManagedElement", "167772252");
		pmTPSelectList[0] = meName;
		String period = "15";
		String startTime = "20240307000000.0";
		String endTime ="20240305000000.0";
		boolean forceUpload = false;
		pmMgr.createPMCollectionTask(taskName, destination, userName, password, emsUserName, pmTPSelectList, period, startTime, endTime, forceUpload);
	}
	
	public List<CollectTaskInfo_T> selectPMCollectionTask(CorbaLoginRes login) throws ProcessingFailureException, UnsupportedEncodingException {
		Common_IHolder commonHolder = new Common_IHolder();
		login.getEmsSession().getManager("PerformanceManagement", commonHolder);
		PerformanceManagementMgr_I pmMgr = PerformanceManagementMgr_IHelper.narrow(commonHolder.value);
		//String[] taskNameList = {new String("SDHLike 15分钟性能事件周期转储".getBytes("iso-8859-1"))};
		String[] taskNameList = {"aaa"};
		CollectTaskInfoList_THolder taskInfoList = new CollectTaskInfoList_THolder();
		String emsUserName = "admin";
		pmMgr.selectPMCollectionTask(taskNameList, emsUserName, taskInfoList);
		return Arrays.asList(taskInfoList.value);
	}
	
	private String parseAny(Any any, DynAnyFactory factory){
		if( null==any ){
			return null;
		}
		StringBuffer result = new StringBuffer();
		try {
			switch (any.type().kind().value()) {
			case TCKind._tk_char:
				result.append(any.extract_char());
				break;
			case TCKind._tk_null:
				break;
			case TCKind._tk_boolean:
				result.append(any.extract_boolean());
				break;
			case TCKind._tk_short:
				result.append(any.extract_short());
				break;
			case TCKind._tk_long:
				result.append(any.extract_long());
				break;
			case TCKind._tk_double:
				result.append(any.extract_double());
				break;
			case TCKind._tk_float:
				result.append(any.extract_float());
				break;
			case TCKind._tk_octet:
				result.append(any.extract_octet());
				break;
			case TCKind._tk_ulong:
				result.append(any.extract_ulong());
				break;
			case TCKind._tk_string:
				result.append(any.extract_string());
				break;
			case TCKind._tk_enum:
			{
				DynEnum dynEnum = (DynEnum) factory.create_dyn_any(any);
				result.append(dynEnum.get_as_string());
				break;
			}
			case TCKind._tk_any:
			{
				any=factory.create_dyn_any(any).get_any();
				result.append(any);
				break;
			}
			case TCKind._tk_objref:
			{
				result.append(any.extract_Object());
				break;
			}
			case TCKind._tk_struct:
			case TCKind._tk_except:
			{
				DynStruct dynstruct = (DynStruct) factory.create_dyn_any(any);
				org.omg.DynamicAny.NameValuePair[] members = dynstruct.get_members();
				result.append("{");
				for (int i = 0; i < members.length; i++) {
					if(i>0){
						result.append(" ");
					}
					result.append(members[i].id).append(" ").append(this.parseAny(members[i].value, factory));
				}
				result.append("}");
				break;
			}
			case TCKind._tk_union:
				DynUnion dynunion = (DynUnion) factory.create_dyn_any(any);
				result.append(dynunion.member_name()).append(" ");
				result.append(this.parseAny(dynunion.member().to_any(), factory));
				break;
			case TCKind._tk_sequence:
				DynSequence dynseq = (DynSequence) factory.create_dyn_any(any);
				Any[] contents = dynseq.get_elements();
				result.append("{");
				for (int i = 0; i < contents.length; i++){
					result.append(parseAny(contents[i], factory));
				}
				result.append("}");
				break;
			case TCKind._tk_array:
				DynArray dynarray = (DynArray) factory.create_dyn_any(any);
				Any[] array_contents = dynarray.get_elements();
				result.append("{");
				for (int i = 0; i < array_contents.length; i++){
					result.append(parseAny(array_contents[i], factory)).append("");
				}
				result.append("}");
				break;
			default:
				result.append(any.type().kind().value());
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		try {
			return new String(result.toString().getBytes("iso-8859-1"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
    
}
